<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>add Result</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
 <%
     String goodname=request.getParameter("goodname");
     String price=request.getParameter("price");
     String area=request.getParameter("area");
     String url="jdbc:mysql://localhost:3306/bookstore?user=root&password=root";
     Class.forName("com.mysql.jdbc.Driver");
     Connection Con=DriverManager.getConnection(url);
     //创建数据库连接
     Statement stm=null;
     ResultSet rs=null;
          stm=Con.createStatement();
          String query="select * from goodinfo where goodname='"+goodname+"'";
          rs = stm.executeQuery(query);
          if(rs.next()==true)
          {out.println("该商品已存在！<a href=\"http://127.0.0.1:8080/homework2/addgood.jsp\">点击返回注册页面</a>");}
            else{
                 String condition="INSERT INTO user VALUES('"+goodname+"','"+price+"','"+area+"')";
                 stm.executeUpdate(condition);
                 out.println("添加成功，返回添加界面继续添加！<a href=\"http://127.0.0.1:8080/homework2/addgood.jsp\">点击返回登陆页面</a>");}
                 
          
       rs.close();//关闭ResultSet对象
       stm.close();//关闭Statement对象
       Con.close();//关闭Connection对象
%>
  </body>
</html>
